<template>
	<view class="page">
		<view class="tabs-wrap">
			<view class="tabs" @click="changeTab(index)" :class="index==i?'active':''" v-for="(item,index) in listTab">
				{{item.name}}
			</view>
		</view>
		<view class="main">
			<view class="lists-wrap">
				<view class="lists" v-for="(item,index) in list" :key="index">
					<image class="icon" src="../../../static/img/integral-icon.png"></image>
					<view class="content">
						<view class="name-wrap flexACB">
							<view class="label">
								{{item.miaoshu}}
							</view>
							<view class="scope">
								积分:{{item.showNum}}
							</view>
						</view>
						<view class="desc-wrap flexACB">
							<view class="tiem">
								{{item.createTime}}
							</view>
							<view class="yong" v-if="item.type==1">
								消耗
							</view>
							<view class="shou" v-if="item.type==0">
								收获
							</view>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" />
			<u-empty v-if="status!='loading'&&list.length==0"
			        mode="data"
			        icon="http://cdn.uviewui.com/uview/empty/list.png"
			>
			</u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listTab: [{
					name: '全部',
					type:'',
				}, {
					name: '收获',
					type:'0',
				}, {
					name: '消耗',
					type:'1',
				}, ],
				i:0,
				list:[],
				status:'loading',//loading / nomore
				pageIndex:1,
				total:0,
			};
		},
		onLoad() {
			this.getList();
		},
		methods: {
			// tab切换
			changeTab(index){
				console.log(index)
				this.i = index;
				this.pageIndex = 1;
				this.getList();
			},
			getList(){
				this.status = 'loading';
				// "type": "" 不传--全部；0--收入；1--支出
				let pageIndex = this.pageIndex;
				let type = this.listTab[this.i].type;
				this.$api.member.getJifenNoteList({pageIndex,type}).then(res => {
					// console.log(res)
					
					if(res.code==200){
						let list = res.rows;
						if(pageIndex==1){
							this.list = list
						}else{
							this.list = this.list.concat(list)
						}
						this.total = res.total;
						if(this.list.length<res.total){
							this.status = 'loadmore';
						}else{
							this.status = 'nomore';
						}
					}
				})
			},
		},
		//上拉加载
		onReachBottom() {
			if(this.status == 'nomore'){
				return false
			}
			this.pageIndex++;
			this.getList();
		},
	}
</script>

<style lang="scss" scoped>
	.page {
		background-color: #F5F5F5;
		min-height: 100vh;

		.tabs-wrap {
			background-color: #fff;
			height: 96rpx;
			display: flex;

			.tabs {
				height: 100%;
				flex: 1;
				text-align: center;
				font-size: 32rpx;
				font-weight: bold;
				position: relative;
				line-height: 96rpx;

				&.active {
					&::after {
						content: '';
						position: absolute;
						bottom: 12rpx;
						width: 36rpx;
						height: 6rpx;
						background: #EC2424;
						border-radius: 3rpx !important;
						left: 50%;
						transform: translateX(-50%);
					}

				}
			}
		}

		.main {
			position: relative;
			padding: 24rpx 30rpx;
		}
	}

	.lists-wrap {
		width: 100%;
		box-shadow: 0px 4rpx 20rpx 0px rgba(75, 74, 85, 0.02);
		border-radius: 16rpx;
		padding: 0 26rpx 0 20rpx;
		background-color: #ffffff;
	}

	.lists {
		width: 100%;
		padding: 24rpx 0 20rpx;
		border-bottom: 1px solid #EBEBEB;
		display: flex;

		&:last-child {
			border-bottom: 1px solid transparent;
		}

		.icon {
			width: 68rpx;
			height: 68rpx;
			flex-shrink: 0;
		}

		.content {
			flex: 1;
			padding-left: 24rpx;

			.name-wrap {
				width: 100%;
				margin-bottom: 8rpx;

				.label {
					font-size: 30rpx;
				}

				.scope {
					font-size: 30rpx;
					font-weight: bold;
				}
			}

			.desc-wrap {
				width: 100%;

				.tiem {
					color: #AAAAAA;
				}

				.yong {
					color: #FFB14D;
				}

				.shou {
					color: #DB1A22;
				}
			}
		}

	}
</style>